// 定义依赖项和插件
var gulp = require('gulp'),
    gutil = require('gulp-util'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    useref = require('gulp-useref'),
    gulpif = require('gulp-if'),
    minifyCss = require('gulp-minify-css'),
    jshint = require('gulp-jshint'),
    babel = require('gulp-babel'),
    livereload = require('gulp-livereload');

// 定义任务
gulp.task('jshint', function(){
    return gulp.src('app/js/**')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});
gulp.task('merge', function(){
    return gulp.src(['app/login.html', 'app/index.html'])
        .pipe(useref())
        .pipe(gulpif('js/login.min.js', uglify()))
        .pipe(gulpif('js/index.min.js', uglify()))
        .pipe(gulpif('*.css', minifyCss()))
        .pipe(gulp.dest('dist'));
});
gulp.task('copy', function(){
    gulp.src('app/bower_components/ckeditor/**')
        .pipe(gulp.dest('dist/js/'));
    gulp.src('app/images/*')
        .pipe(gulp.dest('dist/images/'));
    gulp.src('app/views/*')
        .pipe(gulp.dest('dist/views/'));
    gulp.src('app/bower_components/font-awesome/fonts/*')
        .pipe(gulp.dest('dist/fonts/'));
    gulp.src('app/favicon.ico')
        .pipe(gulp.dest('dist/'));
});
gulp.task('babel', function(){
    return gulp.src('app/es6/*.es6')
        .pipe(babel({
            presets: ['es2015']
        }))
        .pipe(gulp.dest('app/es6/'));
});

// 定义默认任务
gulp.task('default', ['merge', 'copy']);